package br.mendonca.gmgraphlib;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class EdgeList extends ArrayList<List<Integer>> implements Iterator<Edge> {

	private static final long serialVersionUID = -1602314549480567773L;
	protected int v1Index = 0;
	protected int v2Index = 0;

	public abstract void addEdge(int v1, int v2);
	public abstract List<Integer> getNeighborsIndex(int vertexIndex);

	public EdgeList(int numberOfVertices) {
		super(numberOfVertices);

		for (int i = 0; i < numberOfVertices; i++) {
			addNewVertex(numberOfVertices);
		}
	}

	protected abstract void addNewVertex(int numberOfVertices);

	public EdgeList() {
		super();
	}

	public void remove() {
		throw new UnsupportedOperationException();		
	}
	
	public Edge next() {
		Edge edge = new Edge(v1Index + 1, v2Index + 1);		
		updateIndexes();
		
		return edge;
	}
	
	protected void updateIndexes() {
		v2Index++;
		if (v2Index == get(v1Index).size()) {
			v1Index++;
			v2Index = 0;
		}
	}

}